package webTest.context;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.FileReader;
import java.io.IOException;
import java.util.Properties;

/**
 * Created by IFT8
 * Date: 2014/12/30 17:18
 */
public class ServletProperties extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.getWriter().println("ServletProperties");
        String path = this.getServletContext().getRealPath("/config.properties");
        Properties properties = new Properties();
        FileReader file = new FileReader(path);
        properties.load(file);
        String value = properties.getProperty("name");
        response.getWriter().println(value);

        //普通类加载配置文件方法
        PropClassLoad propClassLoad = new PropClassLoad();
        String name =propClassLoad.getName();
        response.getWriter().println("name=" + name);
    }
}
